<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h5>call的一些应用</h5>
  <p>
    funA.call(funB, arg1, arg2,...) 相当于 funB 下面有一个 funA 方法
  </p>
  <script>
    function Animal() {
      this.name = "Animal";
      this.showName = function () {
        alert(this.name);
      }
    }

    function Cat() {
      this.name = "Cat";
    }

    var animal = new Animal();
    var cat = new Cat();

    //通过call或apply方法，将原本属于Animal对象的showName()方法交给对象cat来使用了。    
    //输入结果为"Cat"    
    animal.showName.call(cat, ",");
    //animal.showName.apply(cat,[]);

    function add(a,b){
      console.log(a+b)
    }
    function sum(a,b){
      console.log(a-b)
    }
    add.call(sum, 3, 1)
    sum.call(add, 3, 1)
    // sum(3,1)
  </script>
</body>

</html>